package com.car.account.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.car.account.dto.storesDto.SelectClerkDto;
import com.car.account.entity.Stores;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 董旭
 * @since 2024-08-28
 */
@Mapper
public interface StoresMapper extends BaseMapper<Stores> {

    @Select({
            "<script>",
            "SELECT s.clerk_id AS clerkId, s.clerk_name AS clerkName, s.clerk_phone AS clerkPhone, sr.role_name AS roleName, s.clerk_state AS clerkState",
            "FROM stores s",
            "JOIN cler_role cr ON s.clerk_id = cr.clerk_id",
            "JOIN stores_role sr ON cr.role_id = sr.role_id",
            "<where>",
            "s.stores_id = #{storesId}",
            "AND s.clerk_name LIKE CONCAT('%', #{clerkName}, '%')",
            "AND s.clerk_phone LIKE CONCAT('%', #{clerkPhone}, '%')",
            "<if test=\"clerkState != null\">",
            "AND s.clerk_state = #{clerkState}",
            "</if>",
            "</where>",
            "ORDER BY s.clerk_id ASC",
            "</script>"
    })
    Page<SelectClerkDto> findClerkInfo(Page<SelectClerkDto> page,
                                       @Param("storesId") Integer storesId,
                                       @Param("clerkName") String clerkName,
                                       @Param("clerkPhone") String clerkPhone,
                                       @Param("clerkState") Integer clerkState);

}
